﻿using DevExpress.ExpressApp;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aztall.Module.BusinessObjects
{
	public static class CostMetricCode
	{
		#region fix promo cost 
		public const string PerPromotion = "1010";  // = MetricValue$, e.g. TV advertisement, $50,000
		#endregion

		#region promo costs depend on customer/sku/promotion days
		public const string PerEachCustomer = "1011";  // = MetricValue$ * (no. of customers)
		public const string PerCustomer = "1012";  // = MetricValue$ for a specific customer, e.g. subsidize $2000 for customer C1
		public const string PerEachSku = "1013";  // = MetricValue$ * (no. of sku)
		public const string PerSku = "1014";  // = MetricValue$ for a specific sku, e.g. subsidize $1500 for sku123 
		public const string PerDay = "1015";  // = MetricValue$ * Promotion Days
		#endregion

		#region promo costs depend on volume
		public const string PerPromoUplift = "2011";    // = MetricValue$ * (Uplift of the promotion)
		public const string PerPromoCANN = "2012";    // = MetricValue$ * (CANN of the promotion)
		public const string PerPromoPPD = "2013";    // = MetricValue$ * (PPD of the promotion)
		public const string PerActualVol = "2014";    // = MetricValue$ * (ActualVol during promotion)
		public const string PerBaseVol = "2015";    // = MetricValue$ * (BaseVol during promotion)

		public const string PerPromoVol = "2050";    // = 2011 + 2012 + 2013
		public const string PerProjectVol = "2051";    // = 2015 + 2050

		public const string PercentPerPromoUplift = "3011";   // = MetricValue% / 100 * UnitPrice * (uplift)
		public const string PercentPerPromoCANN = "3012";   // = MetricValue% / 100 * UnitPrice * (CANN)
		public const string PercentPerPromoPPD = "3013";   // = MetricValue% / 100 * UnitPrice * (PPD)
		public const string PercentPerActualVol = "3014";   // = MetricValue% / 100 * UnitPrice * (ActualVol during promotion)
		public const string PercentPerBaseVol = "3015";   // = MetricValue% / 100 * UnitPrice * (BaseVol during promotion)

		public const string PercentPerPromoVol = "3050";   // = 3011 + 3012 + 3013
		public const string PercentPerProjectVol = "3051";   // = 3015 + 3050


		public const string PerRetailBaseVol = "4011";   // = MetricValue$ * (RetailBaseVol in Retail UOM) 
		public const string PerRetailActualVol = "4012";   // = MetricValue$ * (RetailActualVol in Retail UOM) 
		public const string PerRetailPromoVol = "4050";   // = 4012 - 4011

		public const string PercentPerRetailBaseVol = "5010";   // = MetricValue% / 100 * RetailUnitPrice * (RetailBaseVol in Retail UOM) 
		public const string PercentPerRetailActualVol = "5011";   // = MetricValue% / 100 * RetailUnitPrice * (RetailActualVol in Retail UOM) 
		public const string PercentPerRetailPromoVol = "5050";   // = 5011 - 5010

		#endregion

		#region revenue metric 
		// TBD
		#endregion
	}
	public static class VolumeMetricCode
	{
		#region volume metrics
		public const string Uplift = "9010";
		public const string Cann = "9011";
		public const string PPD = "9012";
		public const string Base = "9013";
		public const string Actual = "9014";

		public const string PromoVol = "9050";    //	calculated value, = UpliftVol + CannVol + PPDVol
		public const string ProjectVol = "9051";    // calculated value, ProjectVol = BaseVol + PromoVol = (Actual Vol ideally)

		public const string RetailBaseVol = "9120";
		public const string RetailActualVol = "9121";   // in retail UOM, actual retail volumn 
		public const string RetailPromoVol = "9150";   // in retail UOM, actual retail volumn - base retail volumn
		#endregion
	}
	public static class MetricType
	{
		#region Metric types
		public const string PromoVolume = "PromoVolume";		// Uplift/PPD/CANN
		public const string PromoCost = "Promotion Cost";		// fixed expenses or expenses per day/per sku volume/per customer/per sku
		public const string Revenue = "Revenue";						//a volume x a Cost + fix cost
		public const string SalesVolume = "SalesVolume";		//Baseline/SI/SO/Retail sales

		#endregion
	}
	public static class MetricHelper
	{
		public struct MetricStruct
		{
			public int Oid { get; set; }
			public string MetricCode { get; set; }
			public string MetricDesc { get; set; }
			public string DisplayText { get; set; }
			public MetricScope MetricScope { get; set; }
			public string MetricType { get; set; }
		}
		public static IList<MetricStruct> Metrics = new List<MetricStruct>();

		public static void Init(IObjectSpace os)
		{
			var all = os.GetObjects<Metric>();
			foreach (Metric item in all)
			{
				Metrics.Add(new MetricStruct()
				{
					Oid = item.Oid,
					MetricCode = item.MetricCode,
					MetricDesc = item.MetricDesc,
					MetricScope = item.MetricScope,
					DisplayText = item.DisplayText,
					MetricType = item.MetricType
				}
				);
			}
		}
		public static int GetOid(string metricCode)
		{
			return Metrics.Where(c => c.MetricCode == metricCode).First().Oid;
		}
		public static string GetMetricCode(int metricOid)
		{
			return Metrics.Where(c => c.Oid == metricOid).First().MetricCode;
		}
	}
	public static class StatusHelper
	{
		public struct StatusStruct
		{
			public int Oid { get; set; }
			public string Category { get; set; }
			public string StatusCode { get; set; }
			public string StatusDesc { get; set; }
		}
		public static IList<StatusStruct> Status = new List<StatusStruct>();

		public static void Init(IObjectSpace os)
		{
			var all = os.GetObjects<Status>();
			foreach (Status item in all)
			{
				Status.Add(new StatusStruct()
				{
					Oid = item.Oid,
					Category = item.Category,
					StatusCode = item.StatusCode,
					StatusDesc = item.StatusDesc,
				}
				);
			}
		}
		public static int GetOid(string Category, string StatusCode)
		{
			return Status.Where(c => (c.Category == Category) && (c.StatusCode == StatusCode)).First().Oid;
		}
		public static string GetStatusCode(int statusOid)
		{
			return Status.Where(c => c.Oid == statusOid).First().StatusCode;
		}
	}
}
